home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / subdGivenIntoPolyMode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.8 KB  |  276 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //    Alias|Wavefront Script File
  19. //
  20. //    Creation Date:    Nov 4, 1999
  21. //
  22. //    Procedure:
  23. //        subdIntoPolyMode
  24. //
  25. //    Description:
  26. //        Given a subdivision surface (with no construction history),
  27. //      create a polygon.  For more details see the description
  28. //      with "subdiIntoPolyMode" function below.
  29. //
  30.  
  31. proc subdGivenIntoPolyModeSimple( string $subd, string $poly, int $ap,
  32.                                   int $aut )
  33. //
  34. // Description:
  35. //     See subdGivenIntoPolyMode description.
  36. {
  37.     string $conv[] = `polyToSubdiv -ch 1 -ap $ap -aut $aut -mpc 100000 -o 0 $poly`;
  38.     if( size($conv) > 0 ) {
  39.         // Connect:
  40.         subdTransferUVsToCache $subd $conv[0];
  41.         connectAttr ($conv[0] + ".o") ($subd + ".cr");
  42.     }
  43. }
  44.  
  45. proc subdGivenIntoPolyModeInvolved( string $subd, string $poly, int $ap,
  46.                                     int $aut )
  47. //
  48. // Description:
  49. //     See subdGivenIntoPolyMode description.
  50. {
  51.     string $conv[] = `polyToSubdiv -ch 1 -aut $aut -ap $ap -mpc 100000 -o 0 $poly`;
  52.     if( size($conv) > 0 ) {
  53.  
  54.         // Transfer UVs to Cache before adding the lattice which forces
  55.         // computation of the polyToSubd node, thus leaving the subd with
  56.         // no finer level uvs. Bug #156705.
  57.         //
  58.         subdTransferUVsToCache $subd $conv[0];
  59.  
  60.         string $gpsFirst = "";
  61.         string $gpsLast = "";
  62.         string $newOrig = "";
  63.  
  64.         // Now produce the group parts nodes this object may have.
  65.         // After that, disconnect and delete the newly created subd
  66.         // but reconnect the group parts in there...
  67.         string $lattice[] = `lattice -dv 2 2 2 -oc 0 -ldv 2 2 2 $subd`;
  68.         string $subdHist[] = `listHistory $subd`;
  69.         int $nLat = size($lattice);
  70.         int $nSubdHist = size($subdHist);
  71.         int $hadTweak = false;
  72.         int $ii;
  73.  
  74.         if( $nLat < 3 ) {
  75.             // Something weird happened...
  76.             subdGivenIntoPolyModeSimple( $subd, $poly, $ap, $aut );
  77.             return;
  78.         }
  79.  
  80.         // Start at 1, as [0] is the shape itself.
  81.         for( $ii=1; $ii<$nSubdHist; $ii+=1 ) {
  82.             string $ntype = `nodeType $subdHist[$ii]`;
  83.             if( "tweak" == $ntype ) {
  84.                 $hadTweak = true;
  85.             }
  86.             else if( $hadTweak ) {
  87.                 if( "groupParts" == $ntype ) {
  88.                     if( "" == $gpsLast ) {
  89.                         $gpsLast = $subdHist[$ii];
  90.                         $gpsFirst = $gpsLast;
  91.                     }
  92.                     else {
  93.                         $gpsFirst = $subdHist[$ii];
  94.                     }
  95.                 }
  96.                 else if( "subdiv" == $ntype ) {
  97.                     $newOrig = $subdHist[$ii];
  98.                     break;
  99.                 }
  100.             }
  101.         }
  102.  
  103.         string $tweak[];
  104.         if( "" != $gpsLast ) {
  105.             $tweak = `listConnections -plugs on
  106.                 ($gpsLast + ".outputGeometry")`;
  107.         }
  108.  
  109.         // Something weird happened...
  110.         if( (0 == size($tweak)) ||
  111.             ("" == $gpsFirst) ||
  112.             ("" == $newOrig) ) {
  113.  
  114.             if( "" != $newOrig ) delete $newOrig;
  115.             if( (size($tweak) > 0) && ("" != $tweak[0])) delete $tweak[0];
  116.             delete $lattice[0] $lattice[1] $lattice[2];
  117.             subdGivenIntoPolyModeSimple( $subd, $poly, $ap, $aut );
  118.             return;
  119.         }
  120.  
  121.  
  122.         disconnectAttr ($gpsLast + ".outputGeometry") $tweak;
  123.         disconnectAttr ($newOrig + ".worldSubdiv[0]")
  124.                                         ($gpsFirst + ".inputGeometry");
  125.         disconnectAttr ($lattice[0] + ".outputGeometry[0]")
  126.                                         ($subd + ".create");
  127.  
  128.         connectAttr ($conv[0] + ".o") ($gpsFirst + ".inputGeometry");
  129.         connectAttr ($gpsLast + ".outputGeometry") ($subd + ".cr");
  130.  
  131.         delete $lattice[0] $lattice[1] $lattice[2] $tweak[0] $newOrig;
  132.     }
  133. }
  134.  
  135. global proc string subdGivenIntoPolyMode( string $subd, int $hookAsHist,
  136.                                           int $allowHist, int $templateSubd,
  137.                                           int $ap )
  138. // Description:
  139. //     If $allowHistory is set, we will try and find a polygon in the
  140. //     history of this object, delete that polygon's blind data of
  141. //     the "hierarchical edits" type and put the new blind data on
  142. //     the polygon shape.  If $allowHistory is not set, we will fail
  143. //     if the subd has history in the first place.  If there is no
  144. //     history on the subd, $allowHistory is ignored.  In that case,
  145. //     we will make a new polygon (using "point position" option and
  146. //     the base mesh on the subd -> poly conversion) and give it the blind
  147. //     data that represents the hierarchical edits.  If $hookAsHistory is
  148. //     set, we will then plug everything through polyToSubdiv node into
  149. //     the subd we started with.  Otherwise, we just leave it be.  Note
  150. //     that subd -> poly must be done without history, or we can end up
  151. //     with a loop.
  152. //
  153. //     Ordinarilly, this would be called with a subdivision surface as $subd.
  154. //     However, dagMenuProc.mel may call it with a transform above it instead,
  155. //     so we do a filterExpand, just in case.
  156. {
  157.     global int $gSelectSubdivSurface;
  158.     string $list[] = `filterExpand -ex 1 -fp 1 -sm $gSelectSubdivSurface $subd`;
  159.     int $len = size($list);
  160.     if( $len > 0 ) {
  161.         $subd = $list[0];
  162.     }
  163.  
  164.     int $whichMode = `subdiv -q -proxyMode $subd`;
  165.     if( 2 == $whichMode ) {
  166.         error( "Cannot go into polygon proxy mode on the " +
  167.                "object with construction history and/or deformers." );
  168.         return "";
  169.     }
  170.     else if( 1 == $whichMode ) {
  171.         warning("Already in polygon proxy mode.");
  172.         return "";
  173.     }
  174.  
  175.  
  176.     // We connect shaders to the new poly, if we are templating the subd.
  177.     // Else, this is happening in poly proxy mode and we don't want
  178.     // the shader assignment transferred.
  179.     //
  180.     int $connectShaders = $templateSubd;
  181.  
  182.     string $conn[] = `listConnections ($subd + ".cr")`;
  183.     int $nConn = size($conn);
  184.  
  185.     string $hist[] = `listHistory $subd`;
  186.     int $nHist = size($hist);
  187.  
  188.     string $poly = "";
  189.     int $i;
  190.  
  191.     // If there is no history, we will just see the shape;
  192.     if( ($nConn > 0) && $allowHist ) {
  193.         // Find the polygon to give the blind data
  194.         for( $i=0; $i<$nHist; $i+=1 ) {
  195.             if( "mesh" == `nodeType $hist[$i]` ) {
  196.                 $poly = $hist[$i];
  197.                 break;
  198.             }
  199.         }
  200.     }
  201.     else if( 0 == $nConn ) {
  202.         int $aut = !$ap;
  203.  
  204.         // we need to go and create the polygon
  205.         string $res[] = `subdToPoly -ch 0 -aut $aut -cs $connectShaders -f 1 -d 0 -epp 1 -mp 100000 -cut 1 $subd`;
  206.         if( size($res) > 0 ) {
  207.             // Rename it to something nicer:
  208.             if( $nHist > 0 ) {
  209.                 $poly = `rename $res[0] ($hist[0] + "HistPoly")`;
  210.             }
  211.         }
  212.     }
  213.     else {
  214.         // This is not allowed:
  215.         warning( "Subdivision surface " + $subd +
  216.                  " cannot switch into the polygon mode " +
  217.                  "if it has history and history is not allowed." );
  218.         return "";
  219.     }
  220.  
  221.     // At this point, we should have a $poly; if we don't we quit.
  222.     if( "" == $poly ) {
  223.         warning( "Subdivision surface " + $subd +
  224.                  " cannot switch into the polygon mode " +
  225.                  "if it has history but no polygon in its history." );
  226.         return "";
  227.     }
  228.  
  229.     // OK, we have the polygon.  Go ahead and make the blind stuff:
  230.     if(catch(eval( "subdToBlind -ap " + $ap + " -ic true -izo false " + $subd + " " + $poly))){
  231.         warning("subdToBlind command failure?");
  232.     }
  233.  
  234.     // In some cases, we need the extra poly node; this is when we have
  235.     // more than 127 edits on some faces and thus multiple blind data nodes
  236.     // of the same type.  If we don't do this poly component delete
  237.     // will not work correctly.
  238.     //
  239. /*
  240.     if( `getAttr -size ($poly + ".blindDataNodes")` > 7 ) {
  241.         string $parent[] = `listRelatives -p $poly`;
  242.         string $newPoly = `createNode mesh -p $parent[0]`;
  243.         string $origPoly = `rename $poly ($poly + "Orig")`;
  244.         $newPoly = `rename $newPoly $poly`;
  245.         connectAttr ($origPoly + ".o") ($newPoly + ".i");
  246.         setAttr ($origPoly + ".io") 1;
  247.         $poly = $newPoly;
  248.     }
  249. */
  250.  
  251.     // Now, produce the conversion node: note that that we list the
  252.     // connections on .iog parent attribute.  listHistory seems to
  253.     // mess up after one round of conversion, though it does get cleaned
  254.     // up after a file I/O cycle.  It is always safe to go the involved
  255.     // route, trouble is going "simple" route when you shouldn't.
  256.     // 
  257.     if( $hookAsHist ) {
  258.         // Which one?
  259.         string $iogConn[] = `listConnections ($subd + ".iog")`;
  260.         if( ($nHist > 1) || (0 == size($iogConn)) ) {
  261.             subdGivenIntoPolyModeInvolved( $subd, $poly, $ap, !$ap );
  262.         }
  263.         else {
  264.             subdGivenIntoPolyModeSimple( $subd, $poly, $ap, !$ap );
  265.         }
  266.     }
  267.  
  268.     // Done.  Template the subd if necessary:
  269.     if( $templateSubd ) {
  270.         toggle -template -state on $subd;
  271.     }
  272.  
  273.     return $poly;
  274. }
  275.  
  276.